var fs = require("fs");
var _ = require("lodash");

let fileNameC = "CoreConfig";
let fileName1 = "CoreDes";
let fileName2 = "./data/pa";
let outputFileName = "./data/core.json";

let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString()).map;
let data1 = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString()).map;
let data2 = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString());

let map1 = new Map();
let map2 = new Map();
_.forEach(data1, (e) => {
  let id = e.id;
  let data = e.data;
  map1.set(id, data);
});
_.forEach(data2, (e) => {
  let id = e.id;
  let data = e.data;
  map2.set(id, data);
});
_.forEach(mainData, (e) => {
  if (map1.has(e.id)) {
    _.assign(e.data, map1.get(e.id));
  }
  _.forEach(e.data.coreStage, (e) => {
    let skill1 = e.skillSlot1;
    let skill2 = e.skillSlot2;
    if (skill1 && map2.has(skill1)) {
      e.skill1 = map2.get(skill1);
    }
    if (skill2 && map2.has(skill2)) {
      e.skill2 = map2.get(skill2);
    }
    return e;
  })
});

fs.writeFileSync(outputFileName, JSON.stringify(mainData));
